'use strict';

const moment = require('moment');
const Sequelize = require('sequelize');
const {Model} = Sequelize;

const mysql = require('../common/mysql');

class Enviroment extends Model {}

Enviroment.init({
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    name: {
        type: Sequelize.STRING,
    },
    branch: {
        type: Sequelize.STRING,
    },
    mergeBranch: {
        type: Sequelize.STRING,
    },
    scriptContent: {
        type: Sequelize.STRING,
    },
    lastMergeTime: {
        type: Sequelize.STRING,
    },
    lastMergeLog: {
        type: Sequelize.STRING(2048),
    }
}, {
    sequelize: mysql,
    modelName: 'enviroment',
    timestamps: false
});


class ProjectManage extends Model {}

ProjectManage.init({
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    name: {
        type: Sequelize.STRING,
    },
    gitAddr: {
        type: Sequelize.STRING,
    },
    owner: {
        type: Sequelize.STRING,
    },
    repo: {
        type: Sequelize.STRING,
    },
    isRemoteMerge: {
        type: Sequelize.BOOLEAN
    }
}, {
    sequelize: mysql,
    modelName: 'project_manage',
    timestamps: false
});

Enviroment.belongsToMany(ProjectManage, {through: 'enviroment_project_manage'});
ProjectManage.belongsToMany(Enviroment, {through: 'enviroment_project_manage'});

module.exports = {
    Enviroment,
    ProjectManage
};
